<?php	
    include_once(dirname(__FILE__). "/../../../managers/class.User_Manager.php");
    include_once(dirname(__FILE__). "/../../../managers/class.Region_Manager.php");
    include_once(dirname(__FILE__). "/../../../managers/class.Parameters_Manager.php");
    include_once(dirname(__FILE__). "/../../../managers/class.Picture_Manager.php");
    include_once(dirname(__FILE__). "/../../../treatments/class.Log.php");

    class UserAdministration_Presenter{

        private $user_manager;
        private $region_manager;
        private $picture_manager;
        private $param_manager;

        public function __construct($userId){
            //--initialisation des attibuts
            $this->user_manager = new User_Manager($userId, "../../");
            $this->region_manager = new Region_Manager($userId, "../../");
            $this->param_manager = new Parameters_Manager();
            $this->picture_manager = new Picture_Manager($userId, "../../");
            
            Log::ajoutLignePage($userId, "Administration: Users", "../../");
        }
        
        public function getUserPictureDirectory(){
            return $this->param_manager->getUserPictureDirectory();
        }
        
        public function getAllUser(){
            return $this->user_manager->getAllUser(false);
        }
        
        public function getRegionList(){
            return $this->region_manager->getRegionList();
        }
        
        public function modifyUser($id, $login, $email, $nom, $prenom, $site, $dpt, $actif, $admin){
            $this->user_manager->updateUserByAdmin($id, $login, $email, $nom, $prenom, $site, $dpt, $actif, $admin);
        } 
        
        public function userIsDeletable($user_id){
            return $this->user_manager->userIsDeletable($user_id);
        }
        
        public function deleteUser($id){
            //--Vérifications
            //--Si l'utilisateur à des liens avec des photos on le désactive mais on ne le supprime pas
            $the_user = $this->user_manager->getUserById($id);
            $rep_order_picture = "../../".$this->param_manager->getUserPictureDirectory();
            
            if($the_user->getPhotoProfil() != "Default_white.png"){
                @unlink($rep_order_picture.$the_user->getPhotoProfil());
            }
            
           $this->user_manager->deleteUser($id);
           $this->picture_manager->deleteParcoursUtilisateur($id);
        }
    }